/**
 * 城市/区域名称转换: 汉语转拼音
 */
const fs = require('fs-extra');
const { pinyin } = require('pinyin-pro');
const areaObject = require('./area.json');

(() => {
	const _areaObject = JSON.parse(JSON.stringify(areaObject));

	Object.keys(_areaObject).forEach((city) => {
		const areas = _areaObject[city];

		_areaObject[city] = areas.map((areaData) => {
			const areaName = Object.keys(areaData)[0];

			const pinyinArr = pinyin(areaName, { toneType: 'none', type: 'array' });

			const areaPinyin = pinyinArr.join('');

			return {
				[areaName]: areaPinyin
			}
		});
	});

	fs.writeFileSync('./area1.json', JSON.stringify(_areaObject, null, 4), 'utf8');

	console.log('执行完成');
})();